#include "../mqserver/mq_queue.hpp"
#include <gtest/gtest.h>

castlemq::MsgQueueManager::ptr mqmp;

class MsgqueueTest:public testing::Environment
{
    public:
        virtual void SetUp() override
        {
            mqmp=std::make_shared<castlemq::MsgQueueManager>("./data/meta1.db");
        }

        virtual void TearDown() override
        {
            //emp->clear();
        }
};

TEST(MsgqueueTest,insert_test)
{
    std::unordered_map<std::string, std::string> map {{"k1","v1"},{"k2","v2"},{"k3","v3"}};
    mqmp->declareQueue("queue1",true,false,false,map);
    mqmp->declareQueue("queue2",true,false,false,map);
    mqmp->declareQueue("queue3",true,false,false,map);
    mqmp->declareQueue("queue4",true,false,false,map);
    ASSERT_EQ(mqmp->size(),4);
}

TEST(MsgqueueTest,select_test)
{
    ASSERT_EQ(mqmp->exists("queue1"),true);
    ASSERT_EQ(mqmp->exists("queue2"),true);
    ASSERT_EQ(mqmp->exists("queue3"),false);
    ASSERT_EQ(mqmp->exists("queue4"),true);
    castlemq::MsgQueue::ptr mqp=mqmp->selectQueue("queue2");
    ASSERT_EQ(mqp->name,"queue2");
    ASSERT_EQ(mqp->durable,true);
    ASSERT_EQ(mqp->auto_delete,false);
    ASSERT_EQ(mqp->exclusive,true);
    // ASSERT_EQ(exp->getArgs().c_str(),"k3=v3&k2=v2&k1=v1&");
    ASSERT_EQ(mqp->getArgs(),std::string("k1=v1&k2=v2&k3=v3&"));
}

TEST(MsgqueueTest,remove_test)
{
    mqmp->deleteQueue("queue1");
    castlemq::MsgQueue::ptr emp=mqmp->selectQueue("exchange1");
    ASSERT_EQ(emp.get(),nullptr);
}


int main(int argc,char* argv[])
{
    testing::InitGoogleTest(&argc,argv);
    testing::AddGlobalTestEnvironment(new MsgqueueTest);
    RUN_ALL_TESTS();
    return 0;
}